<?php

/**
 * Display Shifts Offered function
 *
 * Provides Employees Shift Information
 *
 * @author Manas Kalucha <manaskalucha@gmail.com>
 */
include_once 'UTcheckAuth.php';
include_once 'UTerrorcode.php';
include_once 'UTcheckAuth.php';
include_once 'UTDBGlobal.php';

function displayShiftsOffered($userName, $userPass) {
    global $dbaddress;
    global $dbuser;
    global $dbpassword;
    global $dbdatabasename;

    $output = array();
    $HoldDataArray = Array();

    $auth = 0;

    if (checkAuthentication($userName, $userPass) == true) {

        $conn = mysqli_connect($dbaddress, $dbuser, $dbpassword, $dbdatabasename);
        $sql = "select rd.*, r.*, d.*, a.* from roledate rd, dates d, roles r, account a where r.roleID = rd.roleID and d.dateID = rd.dateID and rd.empID = a.empID and rd.shiftStatus = 'Vacant'";
        $result = mysqli_query($conn, $sql);
        $ReturnArray = array();
        if ($result->num_rows > 0) {
            $error = ErrorCode::successRead;
            $ReturnArray[0] = $error;
            while ($row = $result->fetch_assoc()) {
                $HoldDataArray = array();
                $HoldDataArray['roleID'] = $row['roleID'];
                $HoldDataArray['dateID'] = $row['dateID'];
                $HoldDataArray['datestamp'] = $row['datestamp'];
                $HoldDataArray['startTime'] = $row['startTime'];
                $HoldDataArray['endTime'] = $row['endTime'];
                $HoldDataArray['roleName'] = $row['roleName'];
                $HoldDataArray['empID'] = $row['empID'];
                $HoldDataArray['accName'] = $row['accName'];
                $ReturnArray[count($ReturnArray)] = $HoldDataArray;
            }
        }
    } else {
        $error = ErrorCode::authFailRead;
        $ReturnArray = array($error);
    }
    return $ReturnArray;
}

//test code
//$r = displayShiftsOffered('dChen','dChen');
//print_r($r);
?>
